﻿using System;
using System.Data;

using System.Reflection;

namespace   NxPartyAffairsOpen.Helpers
{
    public class EntityHelper
    {    
   
        public static Object ConvertToEntity(DataRow pDataRow, Type pType)
        {
            Object entity = null;
            Object proValue = null;
            PropertyInfo propertyInfo = null;
            try
            {
                if (pDataRow != null)
                {

                    entity = Activator.CreateInstance(pType);
                    foreach (DataColumn dc in pDataRow.Table.Columns)
                    {

                        propertyInfo = pType.GetProperty(dc.ColumnName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
                        proValue = pDataRow[dc];
                        if (propertyInfo != null && proValue!=DBNull.Value)
                            propertyInfo.SetValue(entity, proValue, null);
                    }
                }
            }
            catch
            { }
            return entity;
        }
       
    }
}